package com.flushbonading.classsystem.interceptor;

import com.alibaba.fastjson.JSON;
import com.flushbonading.classsystem.entity.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zyx 2134208960@qq.com
 * @date 2021/6/11 11:31
 * @since 1.0.0
 */
@Slf4j
public class AuthenticationInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getHeader("from")!=null && "gateway".equals(request.getHeader("from"))){
            return true;
        }
        response.setCharacterEncoding("utf-8");
        response.getWriter().write(JSON.toJSONString(CommonResult.hasNoAuthoritativeInformation()));
        log.error("请求被拦截了....");
        return false;
    }
}
